package com.springboot.practice.controller;

import com.springboot.practice.model.Person;
import com.springboot.practice.service.PersonService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/persons")
@RequiredArgsConstructor
public class PersonController {

    private final PersonService personService;

    @GetMapping
    public Person savePerson() {
        Person person = new Person("kings", 30);
        return personService.savePerson(person);
    }

    @GetMapping("/{name}")
    public List<Person> findByName(@PathVariable String name) {
        return personService.findByName(name);
    }
}
